  //
//  KWNQDetailViewController.m
//  KWNClient
//
//  Created by 张明磊 on 14/10/22.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "KWLQDetailViewController.h"
#import "Model_question.h"
#import<CoreText/CoreText.h>
#import "Model_lawyerReply.h"
#import "KWNNetwork.h"
#import "Model_questionDetail.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "KWLLoginViewController.h"
#import "MINavigationController.h"
#import "Model_useAsked.h"
//#import "KWNMyCommentViewController.h"
#import "KWNPhotoDetailViewController.h"
#import "KWLLayerViewController.h"
#import "KWNFeedbackViewController.h"
#import "Model_user.h"
#import "MLBlackTransition.h"
//上拉加载更多
#import "MJRefresh.h"

typedef NS_ENUM(NSInteger, KWNQDetailCellTag)
{
    KWNQDetailCellTag_caina_r       = 100,
    KWNQDetailCellTag_viewBack             ,
    KWNQDetailCellTag_clickCaiNa           ,
    KWNQDetailCellTag_cainaAlter           ,
    KWNQDetailCellTag_loginOut             ,
    KWNQDetailCellTag_imageOne           ,
    KWNQDetailCellTag_imageTwo           ,
};


@interface KWLQDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate,MWPhotoBrowserDelegate,UIActionSheetDelegate>

/**
 下拉刷新
 **/
@property (assign, nonatomic) BOOL reloading;

@property (strong, nonatomic) NSMutableArray *array_data;
@property (weak, nonatomic) UIView *imageView_title;

@property (weak, nonatomic) UIButton *button_caina;

@property (weak, nonatomic) UIButton *button_cancel;
@property (weak, nonatomic) UITextView *textView_input;

@property (weak, nonatomic) UIView *view_input;
@property (strong, nonatomic) NSArray *array_location;
@property (strong, nonatomic) NSMutableArray *array_photo;

#pragma mark - 问题ID -
/**
 *  问题ID
 */
@property (strong, nonatomic) NSString *string_id;

@end

@implementation KWLQDetailViewController

- (id)initWithID:(NSString *)string_id{
    self = [super init];
    if(self){
        _string_id = string_id;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self UI_qDetailTitle];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSArray *array_tmp = @[
                               @"北京",@"上海",@"天津",@"重庆",@"黑龙江省",@"吉林省",@"辽宁省",@"河北省",@"山西省",@"内蒙古自治区",@"山东省",@"安徽省",@"江苏省",@"浙江省",@"江西省",@"福建省",@"河南省",@"湖北省",@"湖南省",@"广东省",@"广西壮族自治区",@"海南省",@"四川省",@"贵州省",@"云南省",@"西藏自治区",@"陕西省",@"甘肃省",@"青海省",@"宁夏回族自治区",@"新疆维吾尔自治区",@"香港特别行政区",@"澳门特别行政区",@"台湾省"];
        dispatch_async(dispatch_get_main_queue(), ^{
            _array_location = array_tmp;
        });
    });
    //[self getQDetailData];
    //[self UI_qDetail];
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated{
    
    UITableView *table = (UITableView *)[self.view viewWithTag:100];
    if(table){
        [self reloadQDetailData];
    }
    else{
        [self getQDetailData];
    }
}

#pragma mark - 获取数据 -
/**
 *   获取数据
 */
- (void)getQDetailData{
// CS 快法务 KLW 2014-12-24
//    [UIUtils view_showProgressHUD:@"加载中,请稍候..." inView:self.view withType:0];
//    
    [SVProgressHUD showWithStatus:@"加载中,请稍候..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
    [[KWNNetwork sharedInstance] question_getQuestionDetailWithID:_string_id FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//        [UIUtils view_hideProgressHUDinView:self.view];
//        
// DE 快法务 KLW 2014-12-24
        switch (stateCode) {
            case 10000:{
// AS 快法务 KLW 2014-12-24
                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                _array_data = result;
                [self UI_qDetail];
            }break;
            case 10003:{
// AS 快法务 KLW 2014-12-24
                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                UIAlertView *alter_loginOut;
                if(IOS8_VERSION){
                    alter_loginOut = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                }
                else{
                    alter_loginOut = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                }
                alter_loginOut.tag = KWNQDetailCellTag_loginOut;
                [alter_loginOut show];
            }break;
            default:{
                NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                
                [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
            }break;
        }
    }];
}

#pragma mark - 下拉刷新列表 -
/**
 *  下拉刷新列表
 */
- (void)reloadQDetailData{
    //[UIUtils view_showProgressHUD:@"加载中,请稍后..." inView:self.view withType:0];
    [[KWNNetwork sharedInstance] question_getQuestionDetailWithID:_string_id FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
        //[UIUtils view_hideProgressHUDinView:self.view];
//        [self reloadEnd];
        UITableView *table_data = (UITableView *)[self.view viewWithTag:100];
        [table_data headerEndRefreshing];

        switch (stateCode) {
            case 10000:{
                _array_data = result;
                UITableView *table_data = (UITableView *)[self.view viewWithTag:100];
                [table_data reloadData];
            }break;
            case 10003:{
                [self qDetailTokenIsFailure];
//                NSString *string_msg  = result[0];
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                
//                double delayInSeconds = 1.5;
//                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//                    //code to be executed on the main queue after delay
//                    KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
//                    [self pushViewController:login];
//                });
                //[self ]
            }break;
            default:{
                NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                
                [SVProgressHUD showErrorWithStatus:string_msg duration:1.5];
// CE 快法务 KLW 2014-12-24
            }break;
        }
    }];
}

#pragma mark - 下拉刷新无下拉动作列表 -
/**
 *  下拉无下拉动作刷新列表
 */
- (void)reloadQDetailDataWithNoDrop{
// CS 快法务 KLW 2014-12-24
//    [UIUtils view_showProgressHUD:@"加载中,请稍候..." inView:self.view withType:0];
//    
    [SVProgressHUD showWithStatus:@"加载中,请稍候..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
    [[KWNNetwork sharedInstance] question_getQuestionDetailWithID:_string_id FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//        [UIUtils view_hideProgressHUDinView:self.view];
//        
// DE 快法务 KLW 2014-12-24
        switch (stateCode) {
            case 10000:{
// AS 快法务 KLW 2014-12-24
                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                _array_data = result;
                UITableView *table_data = (UITableView *)[self.view viewWithTag:100];
                [table_data reloadData];
            }break;
            case 10003:{
// AS 快法务 KLW 2014-12-24
                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                [self qDetailTokenIsFailure];
//                NSString *string_msg  = result[0];
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                
//                double delayInSeconds = 1.5;
//                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//                    //code to be executed on the main queue after delay
//                    KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
//                    [self pushViewController:login];
//                });
                //[self ]
            }break;
            default:{
                NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                
                [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
            }break;
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)UI_qDetailTitle{
    self.view.backgroundColor = RGB(239, 239, 244);
    
    UIView *imageView_title = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44 + IOS7_SIZE)];
    imageView_title.backgroundColor = RGB(91, 165, 229);
    [self.view addSubview:imageView_title];
    _imageView_title = imageView_title;
    
    UIButton *button_menu = [UIButton buttonWithType:UIButtonTypeCustom];
    button_menu.frame = CGRectMake(0, IOS7_SIZE, 60, 45);
    [button_menu setImage:[UIImage imageFileName:@"button_back.png"] forState:UIControlStateNormal];
    [button_menu addTarget:self action:@selector(didClickButton_questionList:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_menu];
    
    
    UILabel *label_title = [[UILabel alloc] initWithFrame:CGRectMake(imageView_title.frame.origin.x,IOS7_SIZE + 5,imageView_title.frame.size.width,35)];
    label_title.backgroundColor = [UIColor clearColor];
    label_title.textColor = RGB(63, 119, 167);
    label_title.textAlignment = NSTextAlignmentCenter;
    label_title.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0f];
    [self.view addSubview:label_title];
    label_title.text = @"问题详情";
    
    UIButton *button_edit = [UIButton buttonWithType:UIButtonTypeCustom];
    button_edit.frame = CGRectMake(250, IOS7_SIZE, 60, 45);
    [button_edit setTitle:@"举报" forState:UIControlStateNormal];
    [button_edit setTitleColor:RGB(63, 119, 167) forState:UIControlStateNormal];
    button_edit.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    [button_edit addTarget:self action:@selector(qDetailReportBtn_click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_edit];

}

- (void)UI_qDetail{
    UITableView *tableView_home = [[UITableView alloc] initWithFrame:CGRectMake(_imageView_title.frame.origin.x, _imageView_title.frame.origin.y + _imageView_title.frame.size.height, _imageView_title.frame.size.width, self.view.frame.size.height - _imageView_title.frame.size.height)];
    tableView_home.backgroundColor = [UIColor clearColor];
    tableView_home.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView_home.delegate = self;
    tableView_home.dataSource = self;
    [self.view addSubview:tableView_home];
    tableView_home.tag = 100;
    
    [tableView_home addHeaderWithCallback:^{
        [self reloadQDetailData];
    }];
//    if (_refreshHeaderView == nil){
//        EGORefreshTableHeaderView *view_header = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0, -50, 320, 60)];
//        view_header.backgroundColor = [UIColor clearColor];
//        view_header.delegate = self;
//        _refreshHeaderView = view_header;
//        [tableView_home addSubview:_refreshHeaderView];
//        [_refreshHeaderView refreshLastUpdatedDate];
//    }
//    _refreshHeaderView.hidden = YES;
    
    UIImageView *imageView_huida = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 63, 320, 65)];
    imageView_huida.image = [UIImage imageFileName:@"image_pinglunBack.png"];
    [self.view addSubview:imageView_huida];
    
    UIButton *button_huida = [UIButton buttonWithType:UIButtonTypeCustom];
    button_huida.frame = CGRectMake(10, imageView_huida.frame.origin.y + 9, 300, 45);
    button_huida.backgroundColor = RGB(91, 165, 229);
    [button_huida setTitle:@"我来回答" forState:UIControlStateNormal];
    button_huida.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
    [button_huida addTarget:self action:@selector(didClickButton_answerQuestion:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_huida];
    button_huida.layer.cornerRadius = 3.0;
    //button_huida.tag = KWNQDetailCellTag_huida;
    
    if([Model_user sharedInstance].bool_isFirst_two){
        UIView *view_d = [[UIView alloc] initWithFrame:self.view.frame];
        [self.view addSubview:view_d];
        view_d.tag = 302;
        
        UIImageView *imageView_three = [[UIImageView alloc] initWithFrame:self.view.frame];
        imageView_three.image = [UIImage imageFileName:@"yindao_three.png"];
        [view_d addSubview:imageView_three];
        
        UIButton *button_one = [UIButton buttonWithType:UIButtonTypeCustom];
        button_one.frame = CGRectMake(102, Iphone5_size(448, 360), 116, 40);
        [button_one setImage:[UIImage imageFileName:@"begin_button_one.png"] forState:UIControlStateNormal];
        [button_one setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button_one addTarget:self action:@selector(didClickButton_three:)forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button_one];
        [Model_user sharedInstance].bool_isFirst_two = NO;
        if(IOS7_VERSION){
            [self.navigationController enabledMLBlackTransition:NO];
        }
        else{
            [self.navigationController_MI setCanDragBack:NO];
        }
    }
}

- (void)didClickButton_questionList:(UIButton *)button{
    [self popViewController];
}

#pragma mark - 举报 -

- (void)qDetailReportBtn_click:(id)sender
{
    
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"举报问题"
                                  delegate:self
                                  cancelButtonTitle:@"取消"
                                  destructiveButtonTitle:nil
                                  otherButtonTitles:@"问题属广告信息、敏感政治内容或其他违规内容", @"手动填写",nil];
    actionSheet.tag = 100;
    [actionSheet showInView:self.view];
}

#pragma mark - UIActionSheetDelegate -


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    //NSLog(@"%i", buttonIndex);
    NSString *buttontitle = [actionSheet buttonTitleAtIndex:buttonIndex];
    if (buttonIndex == actionSheet.cancelButtonIndex) {
        return;
    }
    switch (buttonIndex) {
        case 0:
        {
// CS 快法务 KLW 2014-12-24
//            [UIUtils view_showProgressHUD:@"加载中,请稍候..." inView:self.view withType:0];
//
            [SVProgressHUD showWithStatus:@"加载中,请稍候..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
            [[KWNNetwork sharedInstance]reportWithQuestionId:_string_id andReportStr:buttontitle FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//                [UIUtils view_hideProgressHUDinView:self.view];
//                
// DE 快法务 KLW 2014-12-24
                switch (stateCode) {
                    case 10000:
                    {
// CS 快法务 KLW 2014-12-24
//                        [UIUtils view_showProgressHUD:@"您的举报信息提交成功" inView:self.view withTime:1.5f];
//                        
                        [SVProgressHUD dismissWithSuccess:@"您的举报信息提交成功" afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                    }
                        break;
                    case 10003:
                    {
// AS 快法务 KLW 2014-12-24
                        [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                        [self qDetailTokenIsFailure];
                    }
                        break;
                    default:
                    {
                        NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                        [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                        
                        [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24

                    }
                        break;
                }
            }];
        }
            break;
        case 1:
        {
            KWNFeedbackViewController *feedbackControl = [[KWNFeedbackViewController alloc] initWithQid:_string_id];
            [self pushViewController:feedbackControl];
        }
            break;
        default:
        {
        }
            break;
    }
}
/**
 *  列表数据源
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _array_data.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0)
    {
        static NSString *CellIdentifier = @"Cell_listDetail_wen";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil){
            cell = [[UITableViewCell alloc] init];
            //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            Model_questionDetail *model_detail = _array_data[0];
            
            UITextView *textView_content = [[UITextView alloc] initWithFrame:CGRectMake(10, 60, 280, 200)];
            textView_content.backgroundColor = [UIColor clearColor];
            textView_content.text = model_detail.string_content;
            textView_content.textColor = RGB(93, 93, 93);
            textView_content.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
            textView_content.textAlignment = NSTextAlignmentJustified;
            textView_content.autocorrectionType = UITextAutocorrectionTypeNo;
            textView_content.autocapitalizationType = UITextAutocapitalizationTypeNone;
            textView_content.scrollEnabled = NO;
            [textView_content setEditable:NO];
            
            CGSize size_text = [self contentSizeOfTextView:textView_content];
            textView_content.frame = CGRectMake(textView_content.frame.origin.x, textView_content.frame.origin.y, size_text.width, size_text.height);
            
            UIView *view_b = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, textView_content.frame.size.height + 100)];
            if(model_detail.array_img_small && model_detail.array_img_small.count != 0){
                view_b.frame = CGRectMake(view_b.frame.origin.x, view_b.frame.origin.y, view_b.frame.size.width, view_b.frame.size.height + 51);
            }
            view_b.backgroundColor = [UIColor whiteColor];
            [self.view addSubview:view_b];
            //设置矩形四个圆角半径
            view_b.layer.cornerRadius = 5.0;
            view_b.layer.borderWidth = 1.0;//边框宽度
            view_b.layer.borderColor = RGB(198, 198, 198).CGColor;//边框颜色
            [cell addSubview:view_b];
            [view_b addSubview:textView_content];
            
            UIImageView *imageview_wen = [[UIImageView alloc] initWithFrame:CGRectMake(13, 13, 20, 20)];
            imageview_wen.image = [UIImage imageFileName:@"wen.png"];
            [view_b addSubview:imageview_wen];

            UIImageView *imageView_user = [[UIImageView alloc] initWithFrame:CGRectMake(imageview_wen.frame.origin.x + imageview_wen.frame.size.width + 8, imageview_wen.frame.origin.y + 3, 12, 14)];
            imageView_user.image = [UIImage imageFileName:@"image_free_Person.png"];
            [view_b addSubview:imageView_user];
            
            UILabel *label_name = [[UILabel alloc] initWithFrame:CGRectMake(imageView_user.frame.origin.x + imageView_user.frame.size.width + 15, imageView_user.frame.origin.y + 5, 100, 20)];
            label_name.backgroundColor = [UIColor clearColor];
            NSInteger kind_areaName = model_detail.string_area.integerValue;
            NSString *string_name = _array_location[kind_areaName];
            label_name.text = [NSString stringWithFormat:@"%@网友",string_name];
            label_name.textColor = RGB(209, 209, 209);
            label_name.textAlignment = NSTextAlignmentLeft;
            label_name.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
            [cell addSubview:label_name];
            
            UIView *view_one = [[UIView alloc] initWithFrame:CGRectMake(imageview_wen.frame.origin.x , label_name.frame.origin.y + label_name.frame.size.height - 5, 60, 20)];
            view_one.backgroundColor = RGB(253, 204, 67);
            [view_b addSubview:view_one];
            //设置矩形四个圆角半径
            view_one.layer.cornerRadius = 10.0;
            
            NSInteger kind = model_detail.string_type.integerValue;
            UILabel *label_one = [[UILabel alloc] initWithFrame:view_one.frame];
            label_one.backgroundColor = [UIColor clearColor];
            if(kind < 10){
                label_one.text = @"个人问题";
            }
            else{
                label_one.text = @"公司问题";
            }
            label_one.textColor = RGB(200, 137, 46);
            label_one.textAlignment = NSTextAlignmentCenter;
            label_one.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
            [view_b addSubview:label_one];
            
            UIView *view_three = [[UIView alloc] initWithFrame:CGRectMake(view_one.frame.origin.x + view_one.frame.size.width + 5, view_one.frame.origin.y, 60, 20)];
            view_three.backgroundColor = RGB(253, 204, 67);
            [view_b addSubview:view_three];
            //设置矩形四个圆角半径
            view_three.layer.cornerRadius = 10.0;
            
            NSInteger kind_content = model_detail.string_type.integerValue;
            UILabel *label_three = [[UILabel alloc] initWithFrame:view_three.frame];
            label_three.backgroundColor = [UIColor clearColor];
            switch (kind_content) {
                case 0:{
                    label_three.text = @"婚姻家庭";
                }break;
                case 1:{
                    label_three.text = @"房屋买卖";
                }break;
                case 2:{
                    label_three.text = @"债务纠纷";
                }break;
                case 3:{
                    label_three.text = @"劳动争议";
                }break;
                case 4:{
                    label_three.text = @"交通肇事";
                }break;
                case 5:{
                    label_three.text = @"刑事案件";
                }break;
                case 6:{
                    label_three.text = @"其他类型";
                }break;
                case 11:{
                    label_three.text = @"公司注册";
                }break;
                case 12:{
                    label_three.text = @"投资融资";
                }break;
                case 13:{
                    label_three.text = @"股权期权";
                }break;
                case 14:{
                    label_three.text = @"合同事项";
                }break;
                case 15:{
                    label_three.text = @"知识产权";
                }break;
                case 16:{
                    label_three.text = @"财税事务";
                }break;
                case 17:{
                    label_three.text = @"劳动人事";
                }break;
                case 18:{
                    label_three.text = @"债务纠纷";
                }break;
                case 19:{
                    label_three.text = @"其他问题";
                }break;
                default:
                    break;
            }
            label_three.textColor = RGB(200, 137, 46);
            label_three.textAlignment = NSTextAlignmentCenter;
            label_three.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
            [view_b addSubview:label_three];
            
            if(model_detail.array_img_small.count == 1){
                UIButton *button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
                button_photo.frame = CGRectMake(imageview_wen.frame.origin.x , textView_content.frame.origin.y + textView_content.frame.size.height + 5, 51, 51);
                button_photo.backgroundColor = [UIColor blackColor];
                [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:model_detail.array_img_small[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
                [button_photo addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
                [view_b addSubview:button_photo];
                [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
                button_photo.tag = KWNQDetailCellTag_imageOne;
            }
            else if(model_detail.array_img_small.count == 2){
                UIButton *button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
                button_photo.frame = CGRectMake(imageview_wen.frame.origin.x , textView_content.frame.origin.y + textView_content.frame.size.height + 5, 51, 51);
                button_photo.backgroundColor = [UIColor blackColor];
                [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:model_detail.array_img_small[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
                [button_photo addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
                [view_b addSubview:button_photo];
                [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
                button_photo.tag = KWNQDetailCellTag_imageOne;
                
                UIButton *button_addPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
                button_addPhoto.backgroundColor = [UIColor blackColor];
                button_addPhoto.frame = CGRectMake(button_photo.frame.origin.x + button_photo.frame.size.width + 10 , button_photo.frame.origin.y , 51, 51);
                [button_addPhoto sd_setBackgroundImageWithURL:[NSURL URLWithString:model_detail.array_img_small[1]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
                [button_addPhoto addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
                [view_b addSubview:button_addPhoto];
                [button_addPhoto.imageView setContentMode:UIViewContentModeScaleAspectFit];
                button_addPhoto.tag = KWNQDetailCellTag_imageTwo;
            }
            
            UILabel *label_time = [[UILabel alloc] initWithFrame:CGRectMake(view_one.frame.origin.x, view_b.frame.size.height - 12 - 13, 100, 12)];
            label_time.backgroundColor = [UIColor clearColor];
            label_time.text = model_detail.string_time;
            label_time.textColor = RGB(209, 209, 209);
            label_time.textAlignment = NSTextAlignmentLeft;
            label_time.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
            [view_b addSubview:label_time];
            
            UILabel *label_huida = [[UILabel alloc] initWithFrame:CGRectMake(view_b.frame.size.width - 100 - 13, label_time.frame.origin.y, 100, 12)];
            label_huida.backgroundColor = [UIColor clearColor];
            label_huida.text = [NSString stringWithFormat:@"%@个回答",model_detail.string_count];
            label_huida.textColor = label_time.textColor;
            label_huida.textAlignment = NSTextAlignmentRight;
            label_huida.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
            [view_b addSubview:label_huida];
        }
        return cell;
    }
    else
    {
        NSMutableArray *array_lawyer = _array_data[indexPath.row];
        static NSString *CellIdentifier = @"Cell_listDetail_layer";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell = [[UITableViewCell alloc] init];
            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        //记录每行高度
        int high = 0;
        UIView *view_b;
        for(int i = 0;i<array_lawyer.count;i++)
        {
            if(i == 0)
            {
                Model_lawyerReply *reply = array_lawyer[0];
                UITextView *textView_content = [[UITextView alloc] initWithFrame:CGRectMake(18, 70, 288, 200)];
                textView_content.backgroundColor = [UIColor clearColor
                                                    ];
                textView_content.text = reply.string_reContent;
                textView_content.textColor = RGB(93, 93, 93);
                textView_content.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
                textView_content.textAlignment = NSTextAlignmentNatural;
                textView_content.autocorrectionType = UITextAutocorrectionTypeNo;
                textView_content.autocapitalizationType = UITextAutocapitalizationTypeNone;
                textView_content.scrollEnabled = NO;
                [textView_content setEditable:NO];
                
                CGSize size_text = [self contentSizeOfTextView:textView_content];
                
                
//                CGFloat textView_content_height = [UIUtils heightFor:textView_content.text withFont:textView_content.font labWidth:textView_content.frame.size.width];
//                textView_content_height = textView_content_height + 16;
                
                textView_content.frame = CGRectMake(textView_content.frame.origin.x, textView_content.frame.origin.y, textView_content.frame.size.width, size_text.height);
                
                view_b = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, textView_content.frame.size.height + 200)];
                view_b.backgroundColor = [UIColor whiteColor];
                [self.view addSubview:view_b];
                //设置矩形四个圆角半径
                view_b.layer.cornerRadius = 5.0;
                view_b.layer.borderWidth = 1.0;//边框宽度
                view_b.layer.borderColor = RGB(198, 198, 198).CGColor;//边框颜色
                [cell addSubview:view_b];
                [cell addSubview:textView_content];
                view_b.tag = KWNQDetailCellTag_viewBack;
                
                UIImageView *imageView_caina_r = [[UIImageView alloc] initWithFrame:CGRectMake(view_b.frame.size.width - 45, 8, 45, 54)];
                imageView_caina_r.image = [UIImage imageFileName:@"imageView_caina_r.png"];
                [cell addSubview:imageView_caina_r];
                imageView_caina_r.tag = KWNQDetailCellTag_caina_r;
                
                switch (reply.string_reState.integerValue) {
                    case 0:{
                        imageView_caina_r.hidden = YES;
                    }break;
                    case 1:{
                        imageView_caina_r.hidden = NO;
                    }break;
                    case 2:{
                        imageView_caina_r.image = [UIImage imageFileName:@"imageView_caina_j.png"];
                    }break;
                    default:
                        break;
                }
                
                UIImageView *imageView_portrait = [[UIImageView alloc] initWithFrame:CGRectMake(23, 23, 45, 45)];
                [imageView_portrait setContentMode:UIViewContentModeScaleAspectFill];
                [imageView_portrait sd_setImageWithURL:[NSURL URLWithString:reply.string_imagePath] placeholderImage:[UIImage imageFileName:Default_portrait]];
                [cell addSubview:imageView_portrait];
                imageView_portrait.layer.masksToBounds = YES;
                imageView_portrait.layer.cornerRadius = 22.0;
                imageView_portrait.layer.borderWidth = 1.0;//边框宽度
                imageView_portrait.layer.borderColor = RGB(228, 228, 228).CGColor;//边框颜色
                
                UIButton *button_portrait = [UIButton buttonWithType:UIButtonTypeCustom];
                button_portrait.frame = CGRectMake(23, 23, 45, 45);
                button_portrait.backgroundColor = [UIColor clearColor];
                [button_portrait addTarget:self action:@selector(didClickButton_portrait:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:button_portrait];
                button_portrait.layer.masksToBounds = YES;
                button_portrait.layer.cornerRadius = 22.0;
                button_portrait.layer.borderWidth = 1.0;//边框宽度
                button_portrait.layer.borderColor = RGB(228, 228, 228).CGColor;//边框颜色
                button_portrait.tag = indexPath.row;
                
                UILabel *label_name = [[UILabel alloc] initWithFrame:CGRectMake(button_portrait.frame.origin.x + button_portrait.frame.size.width + 5, button_portrait.frame.origin.y, 80, 20)];
                label_name.backgroundColor = [UIColor clearColor];
                label_name.text = [NSString stringWithFormat:@"%@律师",reply.string_name];
                label_name.textColor = RGB(209, 209, 209);
                label_name.textAlignment = NSTextAlignmentLeft;
                label_name.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
                [cell addSubview:label_name];
                
                UILabel *label_level = [[UILabel alloc] initWithFrame:CGRectMake(label_name.frame.origin.x + label_name.frame.size.width - 5, label_name.frame.origin.y, 40, 20)];
                label_level.backgroundColor = [UIColor clearColor];
                label_level.text = [NSString stringWithFormat:@"LV. %@",reply.string_level];
                label_level.textColor = RGB(69,219,180);
                label_level.textAlignment = NSTextAlignmentLeft;
                label_level.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:15.0f];
                [cell addSubview:label_level];
                
                UIImageView *imageView_title = [[UIImageView alloc] initWithFrame:CGRectMake(label_level.frame.origin.x + label_level.frame.size.width, label_level.frame.origin.y + 1, 58, 18)];
                [cell addSubview:imageView_title];
                switch (reply.string_label.integerValue) {
                    case 0:{
                        imageView_title.image = [UIImage imageFileName:@""];
                    }break;
                    case 1:{
                        imageView_title.image = [UIImage imageFileName:@"layerTitle_daren.png"];
                    }break;
                    case 2:{
                        imageView_title.image = [UIImage imageFileName:@"layerTitle_mingxing.png"];
                    }break;
                    default:
                        break;
                }
                
                UIView *view_one = [[UIView alloc] initWithFrame:CGRectMake(label_name.frame.origin.x, label_name.frame.origin.y + label_name.frame.size.height + 5, 50, 20)];
                view_one.backgroundColor = RGB(88, 236, 198);
                [cell addSubview:view_one];
                //设置矩形四个圆角半径
                view_one.layer.cornerRadius = 10.0;
                
                NSInteger kind_area = reply.int_kind;
                UILabel *label_one = [[UILabel alloc] initWithFrame:view_one.frame];
                label_one.backgroundColor = [UIColor clearColor];
                label_one.text = _array_location[kind_area];
                label_one.textColor = RGB(46, 166, 135);
                label_one.textAlignment = NSTextAlignmentCenter;
                label_one.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
                [cell addSubview:label_one];
                
                UIView *view_two = [[UIView alloc] initWithFrame:CGRectMake(view_one.frame.origin.x + view_one.frame.size.width + 1, view_one.frame.origin.y, 60, 20)];
                view_two.backgroundColor = view_one.backgroundColor;
                [cell addSubview:view_two];
                //设置矩形四个圆角半径
                view_two.layer.cornerRadius = 10.0;
                
                NSInteger kind_content = reply.int_kind;
                UILabel *label_two = [[UILabel alloc] initWithFrame:view_two.frame];
                label_two.backgroundColor = [UIColor clearColor];
                switch (kind_content) {
                    case 0:{
                        label_two.text = @"婚姻家庭";
                    }break;
                    case 1:{
                        label_two.text = @"房屋买卖";
                    }break;
                    case 2:{
                        label_two.text = @"债务纠纷";
                    }break;
                    case 3:{
                        label_two.text = @"劳动争议";
                    }break;
                    case 4:{
                        label_two.text = @"交通肇事";
                    }break;
                    case 5:{
                        label_two.text = @"刑事案件";
                    }break;
                    case 6:{
                        label_two.text = @"其他类型";
                    }break;
                    case 11:{
                        label_two.text = @"公司注册";
                    }break;
                    case 12:{
                        label_two.text = @"投资融资";
                    }break;
                    case 13:{
                        label_two.text = @"股权期权";
                    }break;
                    case 14:{
                        label_two.text = @"合同事项";
                    }break;
                    case 15:{
                        label_two.text = @"知识产权";
                    }break;
                    case 16:{
                        label_two.text = @"财税事务";
                    }break;
                    case 17:{
                        label_two.text = @"劳动人事";
                    }break;
                    case 18:{
                        label_two.text = @"债务纠纷";
                    }break;
                    case 19:{
                        label_two.text = @"其他问题";
                    }break;
                    default:
                        break;
                }
                label_two.textColor = label_one.textColor;
                label_two.textAlignment = NSTextAlignmentCenter;
                label_two.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
                [cell addSubview:label_two];
                
                UIView *view_three = [[UIView alloc] initWithFrame:CGRectMake(view_two.frame.origin.x + view_two.frame.size.width + 1, view_one.frame.origin.y, 60, 20)];
                view_three.backgroundColor = RGB(88, 236, 198);
                [cell addSubview:view_three];
                //设置矩形四个圆角半径
                view_three.layer.cornerRadius = 10.0;
                
                UILabel *label_three = [[UILabel alloc] initWithFrame:view_three.frame];
                label_three.backgroundColor = [UIColor clearColor];
                label_three.textColor = label_one.textColor;
                label_three.text = [NSString stringWithFormat:@"%@年经验",reply.string_year];
                label_three.textAlignment = NSTextAlignmentCenter;
                label_three.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
                [cell addSubview:label_three];
                
                UILabel *label_time = [[UILabel alloc] initWithFrame:CGRectMake(imageView_portrait.frame.origin.x , textView_content.frame.origin.y + textView_content.frame.size.height + 3, 55, 12)];
                label_time.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
                CGSize theStringSize = [reply.string_time sizeWithFont:label_time.font
                                                     constrainedToSize:label_time.frame.size
                                                         lineBreakMode:label_time.lineBreakMode];
                //Adjust the size of the UILable
                label_time.frame = CGRectMake(label_time.frame.origin.x,
                                              label_time.frame.origin.y,
                                              theStringSize.width + 5, theStringSize.height);
                label_time.backgroundColor = [UIColor clearColor];
                label_time.text = reply.string_time;
                
                label_time.textColor = RGB(209, 209, 209);
                label_time.textAlignment = NSTextAlignmentLeft;
                [cell addSubview:label_time];
                
                if(reply.string_in_five.integerValue == 1 && reply.string_first.integerValue == 1){
                    UIImageView *imageView_first = [[UIImageView alloc] initWithFrame:CGRectMake(label_time.frame.origin.x + label_time.frame.size.width + 5, label_time.frame.origin.y + 2, 44, 11)];
                    imageView_first.image = [UIImage imageFileName:@"imageView_first.png"];
                    [cell addSubview:imageView_first];
                    
                    UIImageView *imageView_one = [[UIImageView alloc] initWithFrame:CGRectMake(imageView_first.frame.origin.x + imageView_first.frame.size.width + 10, imageView_first.frame.origin.y, 62, 11)];
                    imageView_one.image = [UIImage imageFileName:@"imageView_one.png"];
                    [cell addSubview:imageView_one];
                }
                else if(reply.string_in_five.integerValue == 0 && reply.string_first.integerValue == 1)
                {
                    UIImageView *imageView_first = [[UIImageView alloc] initWithFrame:CGRectMake(label_time.frame.origin.x + label_time.frame.size.width + 5, label_time.frame.origin.y + 2, 44, 11)];
                    imageView_first.image = [UIImage imageFileName:@"imageView_first.png"];
                    [cell addSubview:imageView_first];
                }
                else if(reply.string_in_five.integerValue == 1 && reply.string_first.integerValue == 0)
                {
                    UIImageView *imageView_one = [[UIImageView alloc] initWithFrame:CGRectMake(label_time.frame.origin.x + label_time.frame.size.width + 5, label_time.frame.origin.y + 2, 62, 11)];
                    imageView_one.image = [UIImage imageFileName:@"imageView_one.png"];
                    [cell addSubview:imageView_one];
                }
                
                UIImageView *imageView_pingjia = [[UIImageView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 10 - 13 - 89 - 75, label_time.frame.origin.y + label_time.frame.size.height + 10, 117, 20)];
                imageView_pingjia.image = [UIImage imageFileName:@"imageView_pingjia.png"];
                [cell addSubview:imageView_pingjia];
                
                UIButton *button_dianzan = [UIButton buttonWithType:UIButtonTypeCustom];
                button_dianzan.frame = CGRectMake(cell.frame.size.width - 10 - 13 -89, imageView_pingjia.frame.origin.y - 7, 89, 35);
                button_dianzan.backgroundColor = [UIColor clearColor];
                [button_dianzan setTitleEdgeInsets:UIEdgeInsetsMake(0, 35, 0, 0)];
                [button_dianzan setTitle:reply.string_evaluateConut forState:UIControlStateNormal];
                [button_dianzan setBackgroundImage:[UIImage imageFileName:@"button_dianzan.png"] forState:UIControlStateNormal];
                [button_dianzan setBackgroundImage:[UIImage imageFileName:@"button_dianzan_s.png"] forState:UIControlStateHighlighted];
                [button_dianzan addTarget:self action:@selector(didClickButton_zan:)forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:button_dianzan];
                button_dianzan.tag = indexPath.row;
                
                high = button_dianzan.frame.origin.y + button_dianzan.frame.size.height;
            }
            else if(i%2 != 0)
            {
                Model_useAsked *model_ask = [array_lawyer objectAtIndex:i];
                
                UIView *view_line = [[UIView alloc] initWithFrame:CGRectMake(30, high + 13, 260, 1)];
                view_line.backgroundColor = RGB(232,232,232);
                [cell addSubview:view_line];
                
                UIImageView *imageView_huida = [[UIImageView alloc] initWithFrame:CGRectMake(23, view_line.frame.origin.y + 13, 38, 18)];
                imageView_huida.image = [UIImage imageFileName:@"imageDetail_zhuiwen.png"];
                [cell addSubview:imageView_huida];
                
//                UITextView *textView_content_reply = [[UITextView alloc] initWithFrame:CGRectMake(18, view_line.frame.origin.y + 32, 280, 200)];
                UITextView *textView_content_reply = [[UITextView alloc] initWithFrame:CGRectMake(19, view_line.frame.origin.y + 0, 286, 200)];
                textView_content_reply.backgroundColor = [UIColor clearColor];
//                textView_content_reply.text = [NSString stringWithFormat:@"%@",model_ask.string_content];
//                textView_content_reply.textColor = RGB(93, 93, 93);
//                textView_content_reply.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
                textView_content_reply.textAlignment = NSTextAlignmentNatural;
                textView_content_reply.autocorrectionType = UITextAutocorrectionTypeNo;
                textView_content_reply.autocapitalizationType = UITextAutocapitalizationTypeNone;
                textView_content_reply.scrollEnabled = NO;
                [textView_content_reply setEditable:NO];
                
                [self setTextViewLineHightAndFontAndColor:textView_content_reply withContentStr:[NSString stringWithFormat:@"%@",model_ask.string_content] withfirstLineHeadIndent:40.0];

                CGSize size_text_reply = [self contentSizeOfTextView:textView_content_reply];
                
//                CGFloat textView_content_height = [UIUtils heightFor:textView_content_reply.text withFont:textView_content_reply.font labWidth:textView_content_reply.frame.size.width];
//                textView_content_height = textView_content_height + 16;
                
                textView_content_reply.frame = CGRectMake(textView_content_reply.frame.origin.x, textView_content_reply.frame.origin.y, textView_content_reply.frame.size.width, size_text_reply.height);
                [cell addSubview:textView_content_reply];
                
                if(model_ask.array_img.count == 1){
                    UIButton *button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
                    button_photo.frame = CGRectMake(imageView_huida.frame.origin.x , textView_content_reply.frame.origin.y + textView_content_reply.frame.size.height + 5, 51, 51);
                    button_photo.backgroundColor = [UIColor blackColor];
                    [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:model_ask.array_img[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
                    [button_photo addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:button_photo];
                    [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
                    button_photo.tag = KWNQDetailCellTag_imageOne;
                }
                else if(model_ask.array_img.count == 2){
                    UIButton *button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
                    button_photo.frame = CGRectMake(imageView_huida.frame.origin.x , textView_content_reply.frame.origin.y + textView_content_reply.frame.size.height + 5, 51, 51);
                    button_photo.backgroundColor = [UIColor blackColor];
                    [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:model_ask.array_img[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
                    [button_photo addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:button_photo];
                    [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
                    button_photo.tag = KWNQDetailCellTag_imageOne;
                    
                    UIButton *button_addPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
                    button_addPhoto.backgroundColor = [UIColor blackColor];
                    button_addPhoto.frame = CGRectMake(button_photo.frame.origin.x + button_photo.frame.size.width + 10 , button_photo.frame.origin.y , 51, 51);
                    [button_addPhoto sd_setBackgroundImageWithURL:[NSURL URLWithString:model_ask.array_img[1]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
                    [button_addPhoto addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:button_addPhoto];
                    [button_addPhoto.imageView setContentMode:UIViewContentModeScaleAspectFit];
                    button_addPhoto.tag = KWNQDetailCellTag_imageTwo;
                }
                
                UILabel *label_time;
                if(model_ask.array_img && model_ask.array_img.count != 0){
                    label_time = [[UILabel alloc] initWithFrame:CGRectMake(imageView_huida.frame.origin.x , textView_content_reply.frame.origin.y + textView_content_reply.frame.size.height + 70, 55, 12)];
                    label_time.backgroundColor = [UIColor clearColor];
                    label_time.text = model_ask.string_time;
                    label_time.textColor = RGB(209, 209, 209);
                    label_time.textAlignment = NSTextAlignmentLeft;
                    label_time.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
                    [cell addSubview:label_time];
                }
                else{
                    label_time = [[UILabel alloc] initWithFrame:CGRectMake(imageView_huida.frame.origin.x , textView_content_reply.frame.origin.y + textView_content_reply.frame.size.height + 3, 55, 12)];
                    label_time.backgroundColor = [UIColor clearColor];
                    label_time.text = model_ask.string_time;
                    label_time.textColor = RGB(209, 209, 209);
                    label_time.textAlignment = NSTextAlignmentLeft;
                    label_time.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
                    [cell addSubview:label_time];
                }
                high = label_time.frame.origin.y + label_time.frame.size.height;
                /*if(array_lawyer.count%2 != 0){
                 view_b.frame = CGRectMake(view_b.frame.origin.x, view_b.frame.origin.y, view_b.frame.size.width, high);
                 }*/
            }
            else{
                Model_useAsked *model_ask = [array_lawyer objectAtIndex:i];
                
                UIView *view_line = [[UIView alloc] initWithFrame:CGRectMake(30, high + 10, 260, 1)];
                view_line.backgroundColor = RGB(232,232,232);
                [cell addSubview:view_line];
                
                UIImageView *imageView_huida = [[UIImageView alloc] initWithFrame:CGRectMake(23, view_line.frame.origin.y + 13, 38, 18)];
                imageView_huida.image = [UIImage imageFileName:@"imageDetail_huida.png"];
                [cell addSubview:imageView_huida];
                
                UITextView *textView_content_reply = [[UITextView alloc] initWithFrame:CGRectMake(19, view_line.frame.origin.y +0, 286, 200)];
                textView_content_reply.backgroundColor = [UIColor clearColor];
//                textView_content_reply.text = [NSString stringWithFormat:@"%@",model_ask.string_content];
//                textView_content_reply.textColor = RGB(93, 93, 93);
//                textView_content_reply.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
                textView_content_reply.textAlignment = NSTextAlignmentNatural;
                textView_content_reply.autocorrectionType = UITextAutocorrectionTypeNo;
                textView_content_reply.autocapitalizationType = UITextAutocapitalizationTypeNone;
                textView_content_reply.scrollEnabled = NO;
                [textView_content_reply setEditable:NO];
                
                
                [self setTextViewLineHightAndFontAndColor:textView_content_reply withContentStr:[NSString stringWithFormat:@"%@",model_ask.string_content] withfirstLineHeadIndent:40.0];

                CGSize size_text_reply = [self contentSizeOfTextView:textView_content_reply];
                
//                CGFloat textView_content_height = [UIUtils heightFor:textView_content_reply.text withFont:textView_content_reply.font labWidth:textView_content_reply.frame.size.width];
//                textView_content_height = textView_content_height + 16;

                textView_content_reply.frame = CGRectMake(textView_content_reply.frame.origin.x, textView_content_reply.frame.origin.y, textView_content_reply.frame.size.width, size_text_reply.height);
                [cell addSubview:textView_content_reply];
                
                UILabel   *label_time = [[UILabel alloc] initWithFrame:CGRectMake(imageView_huida.frame.origin.x , textView_content_reply.frame.origin.y + textView_content_reply.frame.size.height + 3, 55, 12)];
                label_time.backgroundColor = [UIColor clearColor];
                label_time.text = model_ask.string_time;
                label_time.textColor = RGB(209, 209, 209);
                label_time.textAlignment = NSTextAlignmentLeft;
                label_time.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
                [cell addSubview:label_time];
                
                high = label_time.frame.origin.y + label_time.frame.size.height;
                /*if(array_lawyer.count%2 == 0){
                 view_b.frame = CGRectMake(view_b.frame.origin.x, view_b.frame.origin.y, view_b.frame.size.width, high);
                 }*/
            }
        }
        view_b.frame = CGRectMake(view_b.frame.origin.x, view_b.frame.origin.y, view_b.frame.size.width, high + 13);
        return cell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0 && indexPath.section == 0){
        Model_questionDetail *question = _array_data[indexPath.row];
        UITextView *textView_content = [[UITextView alloc] initWithFrame:CGRectMake(20, 5, 280, 200)];
        textView_content.textColor = RGB(93, 93, 93);
        textView_content.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
        textView_content.text = question.string_content;
        
        CGSize size_text = [self contentSizeOfTextView:textView_content];
        if(question.array_img_small && question.array_img_small != 0){
            size_text.height = size_text.height + 55;
        }
        return size_text.height + 110;
    }
    else{
        NSArray *array_lawyer = _array_data[indexPath.row];
        int high = 0;
        for(int i = 0;i<array_lawyer.count;i++){
            if(i == 0){
                Model_lawyerReply *reply = array_lawyer[0];
                UITextView *textView_content = [[UITextView alloc] initWithFrame:CGRectMake(20, 70, 288, 200)];
                textView_content.backgroundColor = [UIColor clearColor];
                textView_content.text = reply.string_reContent;
                textView_content.textColor = RGB(93, 93, 93);
                textView_content.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
                textView_content.textAlignment = NSTextAlignmentNatural;
                
                CGSize size_text = [self contentSizeOfTextView:textView_content];
                
//                CGFloat size_text_height = [UIUtils heightFor:textView_content.text withFont:textView_content.font labWidth:textView_content.frame.size.width];
//                size_text_height = size_text_height + 16;

                high = high + size_text.height + 138;
            }
            else if(i%2 != 0){
                Model_useAsked *model_ask = [array_lawyer objectAtIndex:i];
                UITextView *textView_content_reply = [[UITextView alloc] initWithFrame:CGRectMake(20, 20, 286, 200)];
                textView_content_reply.backgroundColor = [UIColor clearColor];
//                textView_content_reply.text = model_ask.string_content;
//                textView_content_reply.textColor = RGB(93, 93, 93);
//                textView_content_reply.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
                textView_content_reply.textAlignment = NSTextAlignmentNatural;
                
                [self setTextViewLineHightAndFontAndColor:textView_content_reply withContentStr:[NSString stringWithFormat:@"%@",model_ask.string_content] withfirstLineHeadIndent:40.0];

                CGSize size_text_reply = [self contentSizeOfTextView:textView_content_reply];
                
//                CGFloat size_text_reply_height = [UIUtils heightFor:textView_content_reply.text withFont:textView_content_reply.font labWidth:textView_content_reply.frame.size.width];
//                size_text_reply_height = size_text_reply_height + 16;

                if(IOS6_VERSION){
                    high = high + size_text_reply.height + 31;
                }
                else{
                    high = high + size_text_reply.height + 28;
                }
                if(model_ask.array_img && model_ask.array_img.count != 0){
                    high = high + 60;
                }
            }
            else{
                Model_useAsked *model_ask = [array_lawyer objectAtIndex:i];
                UITextView *textView_content_reply = [[UITextView alloc] initWithFrame:CGRectMake(20, 30, 286, 200)];
                textView_content_reply.backgroundColor = [UIColor clearColor];
//                textView_content_reply.text = model_ask.string_content;
//                textView_content_reply.textColor = RGB(93, 93, 93);
//                textView_content_reply.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
                textView_content_reply.textAlignment = NSTextAlignmentNatural;
                
                [self setTextViewLineHightAndFontAndColor:textView_content_reply withContentStr:[NSString stringWithFormat:@"%@",model_ask.string_content] withfirstLineHeadIndent:40.0];

                CGSize size_text_reply = [self contentSizeOfTextView:textView_content_reply];
//                CGFloat size_text_reply_height = [UIUtils heightFor:textView_content_reply.text withFont:textView_content_reply.font labWidth:textView_content_reply.frame.size.width];
//                size_text_reply_height = size_text_reply_height + 16;
                if(IOS6_VERSION){
                    high = high + size_text_reply.height + 68;
                }
                else{
                    high = high + size_text_reply.height + 65;
                }
            }
        }
        Model_questionDetail *model_detail = _array_data[0];
        if(!model_detail.string_adopt_replyid){
            high = high - 50;
            if(indexPath.row == _array_data.count - 1){
                high = high + 80;
            }
        }
        return high + 60;
    }
    return 0;
}

- (CGSize)contentSizeOfTextView:(UITextView *)textView{
    CGSize textViewSize = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, FLT_MAX)];
    return textViewSize;
}

///////
- (CGFloat)textViewHeightCompletion:(CGFloat)height
{
    if (height > 20) {
        return height + 16;
    }
    return height + 8;
}

- (void)setTextViewLineHightAndFontAndColor:(UITextView *)textView withContentStr:(NSString *)str withfirstLineHeadIndent:(CGFloat)indent{
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineHeightMultiple = 22.f;
    paragraphStyle.maximumLineHeight = 22.f;
    paragraphStyle.minimumLineHeight = 15.f;
    paragraphStyle.firstLineHeadIndent = indent;
    //    paragraphStyle.alignment = NSTextAlignmentLeft;
    NSDictionary *attributes = @{ NSFontAttributeName:FontOfHelveticaBold(14), NSParagraphStyleAttributeName:paragraphStyle, NSForegroundColorAttributeName:RGB(93, 93, 93)
                                  };
    textView.attributedText = [[NSAttributedString alloc]initWithString:str attributes:attributes];
    if(IOS6_VERSION){
        textView.center = CGPointMake(textView.center.x, textView.center.y + 3);
    }
}

#pragma mark - 点击采纳问题 -
/**
 *  点击采纳问题
 */
- (void)didClickButton_caina:(UIButton *)button{
    UIAlertView *alter_cana;
    if(IOS8_VERSION){
        alter_cana = [[UIAlertView alloc] initWithTitle:@"是否采纳为最佳答案?" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    }
    else{
        alter_cana = [[UIAlertView alloc] initWithTitle:nil message:@"是否采纳为最佳答案?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    }
    alter_cana.tag = KWNQDetailCellTag_cainaAlter;
    [alter_cana show];
    _button_caina = button;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (alertView.tag) {
        case KWNQDetailCellTag_loginOut:{
            [self.navigationController popToRootViewControllerAnimated:YES];
            double delayInSeconds = 0.7;
            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                //code to be executed on the main queue after delay
                [[NSNotificationCenter defaultCenter] postNotificationName:Notification_KWNLoginOut object:nil];
            });
        }break;
        case KWNQDetailCellTag_cainaAlter:{
            switch (buttonIndex) {
                case 0:{
                    
                }break;
                case 1:{
                    NSMutableArray *array_lawyer = _array_data[1];
                    Model_lawyerReply *question = array_lawyer[_button_caina.tag];
// CS 快法务 KLW 2014-12-24
//                    [UIUtils view_showProgressHUD:@"发送中..." inView:self.view withType:0];
//                    
                    [SVProgressHUD showWithStatus:@"发送中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
                    [[KWNNetwork sharedInstance] question_questionAcceptWithID:question.string_questionID adoptID:question.string_answerId FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//                        [UIUtils view_hideProgressHUDinView:self.view];
//                        
// DE 快法务 KLW 2014-12-24
                        switch (stateCode) {
                            case 10000:{
// AS 快法务 KLW 2014-12-24
                                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                                [self animationAccept];
                                double delayInSeconds = 1.0;
                                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                                    //KWNEvaluateViewController *evaluate = [[KWNEvaluateViewController alloc] initWithQuestionID:question.string_questionID];
                                    //[self pushViewController:evaluate];
                                });
                            }break;
                            case 10003:{
// AS 快法务 KLW 2014-12-24
                                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                                [self qDetailTokenIsFailure];
//                                NSString *string_msg  = result[0];
//                                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                                
//                                double delayInSeconds = 1.5;
//                                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//                                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//                                    //code to be executed on the main queue after delay
//                                    KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
//                                    [self pushViewController:login];
//                                });
                                //[self ]
                            }break;
                            default:{
                                NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                                
                                [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                            }break;
                        }
                    }];
                }break;
                default:
                    break;
            }
        }break;
        case 10003:{
            KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
            [self pushViewController:login];
        }break;
        default:
            break;
    }
}

#pragma mark - 点击追问 -
/**
 *  点击追问
 */
-(void)didClickButton_zhuiwen:(UIButton *)button{
    NSMutableArray *array_lawyer = _array_data[button.tag];
    Model_lawyerReply *question_reply = array_lawyer[0];
    
    Model_questionDetail *question_detail = _array_data[0];
    Model_question *question = [[Model_question alloc] init];
    question.string_qID = question_reply.string_questionID;
    question.string_replyID = question_reply.string_answerId;
    question.int_area = question_detail.string_area.integerValue;
    question.int_kind = question_detail.string_type.integerValue;
    
    [self zhuiWenTanChu_inputKey];
    //KWNAskedViewController *controller_ask = [[KWNAskedViewController alloc] initWithModel:question];
    //[self pushViewController:controller_ask];
}


- (void)zhuiWenTanChu_inputKey{
    if(_view_input){
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        _button_cancel.alpha = 0.6;
        [UIView commitAnimations];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        _view_input.frame = CGRectMake(0, Iphone5_size(150, 44 + IOS7_SIZE), 320, _view_input.frame.size.height);
        [UIView commitAnimations];
        
        [_textView_input becomeFirstResponder];
    }
    else{
        UIButton *button_backCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        button_backCancel.frame = self.view.frame;
        button_backCancel.backgroundColor = [UIColor blackColor];
        button_backCancel.alpha = 0;
        [button_backCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button_backCancel addTarget:self action:@selector(didClickButton_cancel:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button_backCancel];
        _button_cancel = button_backCancel;
        
        UIView *view_input = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 200 + Iphone5_size(20, 0))];
        view_input.backgroundColor = RGB(239,239,244);
        [self.view addSubview:view_input];
        _view_input = view_input;
        
        UIView *view_board = [[UIView alloc] initWithFrame:CGRectMake(10, 50, view_input.frame.size.width - 20, view_input.frame.size.height - Iphone5_size(120, 100))];
        view_board.backgroundColor = [UIColor whiteColor];
        view_board.layer.cornerRadius = 6.0;
        view_board.layer.borderWidth = 1.0;//边框宽度
        view_board.layer.borderColor = RGB(197, 197, 197).CGColor;//边框颜色
        [view_input addSubview:view_board];
        //_view_input = view_input;
        
        UITextView *textView_input = [[UITextView alloc] initWithFrame:CGRectMake(20, view_board.frame.origin.y, view_board.frame.size.width - 20, view_board.frame.size.height)];
        textView_input.backgroundColor = [UIColor clearColor];
        textView_input.textColor = RGB(107, 107, 107);
        textView_input.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        textView_input.autocorrectionType = UITextAutocorrectionTypeNo;
        textView_input.autocapitalizationType = UITextAutocapitalizationTypeNone;
        textView_input.returnKeyType = UIReturnKeyDefault;
        [view_input addSubview:textView_input];
        //textView_input.delegate = self;
        //_textView_content = textView_input;
        //textView_input.tag = 100;
        [textView_input becomeFirstResponder];
        _textView_input = textView_input;
        
        UILabel *label_title = [[UILabel alloc] initWithFrame:CGRectMake(110, 15, 100, 20)];
        label_title.backgroundColor = [UIColor clearColor];
        label_title.text = @"我的回答";
        label_title.textColor = RGB(107, 107, 107);
        label_title.textAlignment = NSTextAlignmentCenter;
        label_title.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
        [view_input addSubview:label_title];
        
        UIButton *button_cancel = [UIButton buttonWithType:UIButtonTypeCustom];
        button_cancel.frame = CGRectMake(10, label_title.frame.origin.y, 50, 20);
        button_cancel.backgroundColor = [UIColor clearColor];
        button_cancel.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
        [button_cancel setTitle:@"取消" forState:UIControlStateNormal];
        [button_cancel setTitleColor:RGB(107, 107, 107) forState:UIControlStateNormal];
        [button_cancel addTarget:self action:@selector(didClickButton_cancel:) forControlEvents:UIControlEventTouchUpInside];
        [view_input addSubview:button_cancel];
        
        UIButton *button_send = [UIButton buttonWithType:UIButtonTypeCustom];
        button_send.frame = CGRectMake(260, label_title.frame.origin.y, 50, 20);
        button_send.backgroundColor = [UIColor clearColor];
        button_send.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
        [button_send setTitle:@"发送" forState:UIControlStateNormal];
        [button_send setTitleColor:RGB(92, 166, 229) forState:UIControlStateNormal];
        [button_send addTarget:self action:@selector(didClickButton_send:) forControlEvents:UIControlEventTouchUpInside];
        [view_input addSubview:button_send];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        view_input.frame = CGRectMake(0, Iphone5_size(150, 44 + IOS7_SIZE), 320, view_input.frame.size.height);
        [UIView commitAnimations];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        button_backCancel.alpha = 0.6;
        [UIView commitAnimations];
    }
}

//#pragma mark - 点击律师头像 -
/**
 *  点击律师头像
 
-(void)didClickButton_portrait:(UIButton *)button{
    NSMutableArray *array_lawyer = _array_data[1];
    Model_lawyerReply *model_reply = array_lawyer[button.tag - 1];
    
    NSString *string_layer_id = model_reply.string_id;
    KWLLayerViewController *controller_layer = [[KWLLayerViewController alloc] initWithLaywerWithID:string_layer_id];
    [self pushViewController:controller_layer];
}*/

#pragma mark - 点击律师头像 -
/**
 *  点击律师头像
 */
-(void)didClickButton_portrait:(UIButton *)button{
    [MobClick event:@"qdetail_portrait"];
    NSMutableArray *array_lawyer = _array_data[button.tag];
    Model_lawyerReply *model_reply = array_lawyer[0];
    NSString *string_layer_id = model_reply.string_id;
    KWLLayerViewController *controller_layer = [[KWLLayerViewController alloc] initWithLaywerWithID:string_layer_id];
    [self pushViewController:controller_layer];
}

#pragma mark - 采纳动画 -
/**
 *  采纳动画
 */
- (void)animationAccept{
    UIImageView *imageView_caina = [[UIImageView alloc] initWithFrame:CGRectMake(56, self.view.frame.size.height/2 - 125, 208, 250)];
    imageView_caina.image = [UIImage imageFileName:@"imageView_caina.png"];
    [self.view addSubview:imageView_caina];
    
    double delayInSeconds = 0.5;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        imageView_caina.transform = CGAffineTransformMakeScale(1.0f, 1.0f);//将要显示的view按照正常比例显示出来
        [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //InOut 表示进入和出去时都启动动画
        [UIView setAnimationDuration:0.5f];//动画时间
        imageView_caina.transform=CGAffineTransformMakeScale(0.01f, 0.01f);//先让要显示的view最小直至消失
        [UIView commitAnimations]; //启动动画
    });
    double delayInSeconds1 = 1.0;
    dispatch_time_t popTime1 = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds1 * NSEC_PER_SEC);
    dispatch_after(popTime1, dispatch_get_main_queue(), ^(void){
        UITableViewCell *cell = [self reciveSuperViewCellWithView:_button_caina];
        UIImageView *imageView_caina_r = (UIImageView *)[cell viewWithTag:KWNQDetailCellTag_caina_r];
        imageView_caina_r.hidden = NO;
        [imageView_caina removeFromSuperview];
    });
}

#pragma mark - 获取上级控件 -
/**
 *  获取上级控件
 */
- (UITableViewCell *)reciveSuperViewCellWithView:(UIView *)view{
    for (UIView *next = [view superview]; next; next = next.superview){
        UIResponder *nextResponder;
        if(IOS8_VERSION){
            nextResponder = [view superview];
        }
        else{
            nextResponder = [next nextResponder];
        }
        if ([nextResponder isKindOfClass:[UITableViewCell class]]){
            return (UITableViewCell *)nextResponder;
        }
    }
    return nil;
}

- (UITableView *)reciveSuperViewTableWithView:(UIView *)view{
    for (UIView *next = [view superview]; next; next = next.superview){
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UITableView class]]){
            return (UITableView *)nextResponder;
        }
    }
    return nil;
}

#pragma mark - 追加评论或查看 -
/**
 *   追加评论或查看
 */
- (void)didClickButton_zhuijia:(UIButton *)button{
    if(button.selected){
       //查看评论
        NSMutableArray *array_lawyer = _array_data[1];
        Model_lawyerReply *reply = array_lawyer[0];
        if(reply){
            //KWNMyCommentViewController *myComment = [[KWNMyCommentViewController alloc] initWIthQuestionID:reply.string_questionID];
            //[self pushViewController:myComment];
        }
    }
    else{
        NSMutableArray *array_lawyer = _array_data[1];
        Model_lawyerReply *reply = array_lawyer[0];
        if(reply){
            //KWNEvaluateViewController *evaluate= [[KWNEvaluateViewController alloc] initWithQuestionID:reply.string_questionID];
            //[self pushViewController:evaluate];
        }
    }
}

#pragma mark - 查看照片 -
/**
 *  查看照片
 */
-(void)didClickButton_addPhoto:(UIButton *)button{
    switch (button.tag) {
        case KWNQDetailCellTag_imageOne:{
            KWNPhotoDetailViewController *detail = [[KWNPhotoDetailViewController alloc] initWithDelegate:self];
            detail.int_tag = 1;
            if(_array_photo){
                [_array_photo removeAllObjects];
                Model_questionDetail *model_detail = _array_data[0];
                [_array_photo addObjectsFromArray:model_detail.array_img];
            }
            else{
                NSMutableArray *array_photo = [NSMutableArray array];
                Model_questionDetail *model_detail = _array_data[0];
                [array_photo addObjectsFromArray:model_detail.array_img];
                _array_photo = array_photo;
            }
            [self presentViewController:detail animated:YES completion:^{
                
            }];
        }break;
        case KWNQDetailCellTag_imageTwo:{
            if(_array_photo){
                [_array_photo removeAllObjects];
            }
            else{
                NSMutableArray *array_photo = [NSMutableArray array];
                _array_photo = array_photo;
            }
            Model_questionDetail *model_detail = _array_data[0];
            NSArray *array_reverse = [[model_detail.array_img reverseObjectEnumerator] allObjects];
            [_array_photo addObjectsFromArray:array_reverse];
            KWNPhotoDetailViewController *detail = [[KWNPhotoDetailViewController alloc] initWithDelegate:self];
            detail.int_tag = 1;
            [self presentViewController:detail animated:YES completion:^{
                
            }];
        }break;
        default:
            break;
    }
}

#pragma mark - 点击游览图片 -
/**
 *  点击游览图片
 */
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
    return _array_photo.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
    MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:_array_photo[index]]];
    return photo;
}

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index{
    switch (_array_photo.count) {
        case 1:{
            [(KWNPhotoDetailViewController *)photoBrowser scrollPageViewToIndex:index andBoolScroll:NO];
        }break;
        case 2:{
            [(KWNPhotoDetailViewController *)photoBrowser scrollPageViewToIndex:index andBoolScroll:YES];
        }break;
        default:
            break;
    }
}
#pragma mark - 点击我来回答 -
/**
 *  点击我来回答
 */
- (void)didClickButton_answerQuestion:(UIButton *)button{
    if(_view_input){
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        _button_cancel.alpha = 0.6;
        [UIView commitAnimations];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        _view_input.frame = CGRectMake(0, Iphone5_size(150, 44 + IOS7_SIZE), 320, _view_input.frame.size.height);
        [UIView commitAnimations];
        
        [_textView_input becomeFirstResponder];
    }
    else{
        UIButton *button_backCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        button_backCancel.frame = self.view.frame;
        button_backCancel.backgroundColor = [UIColor blackColor];
        button_backCancel.alpha = 0;
        [button_backCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button_backCancel addTarget:self action:@selector(didClickButton_cancel:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button_backCancel];
        _button_cancel = button_backCancel;
        
        UIView *view_input = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 200 + Iphone5_size(20, 0))];
        view_input.backgroundColor = RGB(239,239,244);
        [self.view addSubview:view_input];
        _view_input = view_input;
        
        UIView *view_board = [[UIView alloc] initWithFrame:CGRectMake(10, 50, view_input.frame.size.width - 20, view_input.frame.size.height - Iphone5_size(120, 100))];
        view_board.backgroundColor = [UIColor whiteColor];
        view_board.layer.cornerRadius = 6.0;
        view_board.layer.borderWidth = 1.0;//边框宽度
        view_board.layer.borderColor = RGB(197, 197, 197).CGColor;//边框颜色
        [view_input addSubview:view_board];
        //_view_input = view_input;
        
        UITextView *textView_input = [[UITextView alloc] initWithFrame:CGRectMake(20, view_board.frame.origin.y, view_board.frame.size.width - 20, view_board.frame.size.height)];
        textView_input.backgroundColor = [UIColor clearColor];
        textView_input.textColor = RGB(107, 107, 107);
        textView_input.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        textView_input.autocorrectionType = UITextAutocorrectionTypeNo;
        textView_input.autocapitalizationType = UITextAutocapitalizationTypeNone;
        textView_input.returnKeyType = UIReturnKeyDefault;
        [view_input addSubview:textView_input];
        //textView_input.delegate = self;
        //_textView_content = textView_input;
        //textView_input.tag = 100;
        [textView_input becomeFirstResponder];
        _textView_input = textView_input;
        
        UILabel *label_title = [[UILabel alloc] initWithFrame:CGRectMake(110, 15, 100, 20)];
        label_title.backgroundColor = [UIColor clearColor];
        label_title.text = @"我的回答";
        label_title.textColor = RGB(107, 107, 107);
        label_title.textAlignment = NSTextAlignmentCenter;
        label_title.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
        [view_input addSubview:label_title];
        
        UIButton *button_cancel = [UIButton buttonWithType:UIButtonTypeCustom];
        button_cancel.frame = CGRectMake(10, label_title.frame.origin.y, 50, 20);
        button_cancel.backgroundColor = [UIColor clearColor];
        button_cancel.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
        [button_cancel setTitle:@"取消" forState:UIControlStateNormal];
        [button_cancel setTitleColor:RGB(107, 107, 107) forState:UIControlStateNormal];
        [button_cancel addTarget:self action:@selector(didClickButton_cancel:) forControlEvents:UIControlEventTouchUpInside];
        [view_input addSubview:button_cancel];
        
        UIButton *button_send = [UIButton buttonWithType:UIButtonTypeCustom];
        button_send.frame = CGRectMake(260, label_title.frame.origin.y, 50, 20);
        button_send.backgroundColor = [UIColor clearColor];
        button_send.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
        [button_send setTitle:@"发送" forState:UIControlStateNormal];
        [button_send setTitleColor:RGB(92, 166, 229) forState:UIControlStateNormal];
        [button_send addTarget:self action:@selector(didClickButton_send:) forControlEvents:UIControlEventTouchUpInside];
        [view_input addSubview:button_send];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        view_input.frame = CGRectMake(0, Iphone5_size(150, 44 + IOS7_SIZE), 320, view_input.frame.size.height);
        [UIView commitAnimations];
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.2f];
        [UIView setAnimationRepeatCount:1];
        [UIView setAnimationBeginsFromCurrentState:YES];
        button_backCancel.alpha = 0.6;
        [UIView commitAnimations];
    }
}

#pragma mark - 点击取消按钮 -
/**
 *  点击取消按钮
 */
- (void)didClickButton_cancel:(UIButton *)button_cancel{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationBeginsFromCurrentState:YES];
    _view_input.frame = CGRectMake(0, self.view.frame.size.height, 320, _view_input.frame.size.height);
    [UIView commitAnimations];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2f];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationBeginsFromCurrentState:YES];
    _button_cancel.alpha = 0;
    [UIView commitAnimations];
    
    [self.view endEditing:YES];
}

#pragma mark - 点击发送按钮 -
/**
 *  点击发送按钮
 */
- (void)didClickButton_send:(UIButton *)button_send{
    [self didClickButton_cancel:nil];
    if(_textView_input.text && _textView_input.text.length != 0){
// CS 快法务 KLW 2014-12-24
//        [UIUtils view_showProgressHUD:@"发送中..." inView:self.view withType:0];
//        
        [SVProgressHUD showWithStatus:@"发送中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
        [[KWNNetwork sharedInstance] send_answerQuestion:_string_id andText:_textView_input.text FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//            [UIUtils view_hideProgressHUDinView:self.view];
//            
// DE 快法务 KLW 2014-12-24
            switch (stateCode) {
                case 10000:{
                    NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                    [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                    
                    [SVProgressHUD dismissWithSuccess:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                    double delayInSeconds = 1.5;
                    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"notificaition_KWLReloadHome" object:nil];
                        [self.navigationController popToRootViewControllerAnimated:YES];
                    });
                }break;
                case 10003:{
// AS 快法务 KLW 2014-12-24
                    [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                    [self qDetailTokenIsFailure];
//                    NSString *string_msg  = result[0];
//                    [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                    
//                    double delayInSeconds = 1.5;
//                    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//                    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//                        //code to be executed on the main queue after delay
//                        KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
//                        [self pushViewController:login];
//                    });
                    //[self ]
                }break;

                default:{
                    NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                    [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                    
                    [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                }break;
            }
        }];
    }
    else{
// CS 快法务 KLW 2014-12-24
//        [UIUtils view_showProgressHUD:@"回答内容不能为空!" inView:self.view withTime:1.5f];
//        
        [SVProgressHUD showErrorWithStatus:@"回答内容不能为空!" duration:1.5];
// CE 快法务 KLW 2014-12-24
    }
    //[self.view endEditing:YES];
}

#pragma mark - 同行点赞 -
/**
 *  同行点赞
 */
- (void)didClickButton_zan:(UIButton *)button{
// CS 快法务 KLW 2014-12-25
//    NSMutableArray *array_lawyer = _array_data[1];
//    
    NSMutableArray *array_lawyer = _array_data[button.tag];
// CE 快法务 KLW 2014-12-25
    Model_lawyerReply *reply = array_lawyer[0];
// CS 快法务 KLW 2014-12-24
//     [UIUtils view_showProgressHUD:@"发送中..." inView:self.view withType:0];
//    
    [SVProgressHUD showWithStatus:@"发送中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
    [[KWNNetwork sharedInstance] lawyer_didClickGoodButtonWithReplyID:reply.string_answerId FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//        [UIUtils view_hideProgressHUDinView:self.view];
//        
// DE 快法务 KLW 2014-12-24
        switch (stateCode) {
            case 10000:{
// AS 快法务 KLW 2014-12-24
                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
// CS 快法务 KLW 2014-12-19
//                NSString *string_msg  = result[0];
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                [button setTitle:[NSString stringWithFormat:@"%ld",(long)reply.string_evaluateConut.integerValue + 1] forState:UIControlStateNormal];
//                
                [self theAnimationForDianZan];
                double delayInSeconds = 1.0;
                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                    [button setTitle:[NSString stringWithFormat:@"%ld",(long)reply.string_evaluateConut.integerValue + 1] forState:UIControlStateNormal];
                });

// CE 快法务 KLW 2014-12-19
            }break;
            case 10003:{
// AS 快法务 KLW 2014-12-24
                [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                [self qDetailTokenIsFailure];
//                NSString *string_msg  = result[0];
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                
//                double delayInSeconds = 1.5;
//                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//                    //code to be executed on the main queue after delay
//                    KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
//                    [self pushViewController:login];
//                });
                //[self ]
            }break;

            default:{
                NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                
                [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
            }break;
        }
    }];
}

//点赞动画
- (void)theAnimationForDianZan
{
    UIImageView *imageView_dianzan = [[UIImageView alloc] initWithFrame:CGRectMake(56, self.view.frame.size.height/2 - 125, 208, 250)];
    imageView_dianzan.image = [UIImage imageFileName:@"imageView_caina.png"];
    [self.view addSubview:imageView_dianzan];
    
    double delayInSeconds = 0.5;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        imageView_dianzan.transform = CGAffineTransformMakeScale(1.0f, 1.0f);//将要显示的view按照正常比例显示出来
        [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //InOut 表示进入和出去时都启动动画
        [UIView setAnimationDuration:0.5f];//动画时间
        imageView_dianzan.transform=CGAffineTransformMakeScale(0.01f, 0.01f);//先让要显示的view最小直至消失
        [UIView commitAnimations]; //启动动画
    });
    double delayInSeconds1 = 1.0;
    dispatch_time_t popTime1 = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds1 * NSEC_PER_SEC);
    dispatch_after(popTime1, dispatch_get_main_queue(), ^(void){
        //        UITableViewCell *cell = [self reciveSuperViewCellWithView:_button_caina];
        //        UIImageView *imageView_caina_r = (UIImageView *)[cell viewWithTag:KWNQDetailCellTag_caina_r];
        //        imageView_caina_r.hidden = NO;
        [imageView_dianzan removeFromSuperview];
    });
    
}

#pragma mark - 账号被替换下线提示 -
- (void)qDetailTokenIsFailure{
    UIAlertView *alter_login;
    if(IOS8_VERSION){
        alter_login = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    else{
        alter_login = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    alter_login.tag = 10003;
    [alter_login show];
}

- (void)didClickButton_three:(UIButton *)button{
    [button removeFromSuperview];
    UIView *imageViewTwo = (UIView *)[self.view viewWithTag:302];
    [imageViewTwo removeFromSuperview];
    
    if(IOS7_VERSION){
        [self.navigationController enabledMLBlackTransition:YES];
    }
    else{
        [self.navigationController_MI setCanDragBack:YES];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [scrollView didScrollViewToScroll];
}

@end
